package cn.kgc.fxy.smbms.service.impl;

import cn.kgc.fxy.smbms.entity.Bill;
import cn.kgc.fxy.smbms.mapper.BillMapper;
import cn.kgc.fxy.smbms.service.BillService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BillServiceImpl implements BillService {
    @Resource
    private BillMapper billMapper;
    @Override
    public PageInfo<Bill> findBill(Bill condition, Integer pageNum, Integer pageSize) {
        if (pageNum==null){
            pageNum = 1;
        }
        PageHelper.startPage(pageNum,pageSize);
        List<Bill> billList = this.billMapper.selectBill(condition);
        PageInfo<Bill> billPageInfo = new PageInfo<>(billList);
        return billPageInfo;
    }

    @Override
    public Bill findView(Long billId) {
        Bill bill = this.billMapper.selectView(billId);
        return bill;
    }

    @Override
    public void addBill(Bill bill) {
        billMapper.insertBill(bill);
    }

    @Override
    public Integer findBillCount(String billCode) {
        Integer findBillCount = billMapper.selectBillCount(billCode);
        return findBillCount;
    }

    @Override
    public void modifyBill(Bill bill) {
        billMapper.updateBill(bill);
    }

    @Override
    public void removeBill(Long billId) {
        billMapper.deleteBill(billId);
    }
}
